﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.huawei.esdk.tp.professional.eSDKTPProfessionalMCUMgr;
using com.huawei.esdk.tp.professional.DataType;
using com.huawei.esdk.tp.professional.local;
using System.Web.Services.Protocols;
using com.huawei.esdk.tp.professional.Utils;

namespace com.huawei.esdk.tp.professional.local
{
    public partial class MCUMgrServiceEx
    {
        private static string url = com.huawei.esdk.tp.professional.Utils.UtilsSettings.URL + com.huawei.esdk.tp.professional.Utils.UtilsSettings.tpProfessionalMCUMgr;
        private static TPProfessionalMCUMgrService MCUMgr = new TPProfessionalMCUMgrService(url);

        private static MCUMgrServiceEx instance = null;
        protected MCUMgrServiceEx()
        {

        }

        public static MCUMgrServiceEx Instance()
        {
            if (null == instance)
            {
                instance = new MCUMgrServiceEx();
            }
            return instance;
        }

        public TPSDKResponseEx<MCUResourceEx[]> queryMCUFutureResourceEx(int[] mcus, System.DateTime beginTime, string duration)
        {
            MCUMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseEx<MCUResourceEx[]> result = new TPSDKResponseEx<MCUResourceEx[]>();
            try
            {
                MCUResourceEx[] mcuResList;

                result.resultCode = MCUMgr.queryMCUFutureResourceEx(mcus, beginTime, duration, out mcuResList);
                if (result.resultCode == 0)
                {
                    result.result = mcuResList;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }

        public TPSDKResponseSecondEx<MCUInfoEx[], PagesInfoEx> queryMCUInfoEx(QueryConfigEx queryConfig)
        {
            MCUMgr.CookieContainer = AuthorizeServiceEx.cookieJar;
            TPSDKResponseSecondEx<MCUInfoEx[], PagesInfoEx> result = new TPSDKResponseSecondEx<MCUInfoEx[], PagesInfoEx>();
            try
            {
                if (queryConfig.focusItem != null)
                {
                    queryConfig.focusItemSpecified = true;
                }
                queryConfig.focusItemSpecified = true;
                MCUInfoEx[] mcus; 
                PagesInfoEx pageInfo;

                result.resultCode = MCUMgr.queryMCUInfoEx(queryConfig, out mcus, out pageInfo);
                if (result.resultCode == 0)
                {
                    result.result1 = mcus;
                    result.result2 = pageInfo;
                }
                return result;
            }
            catch (SoapHeaderException e)
            {
                int errorCode = ExceptionUtils.processSoapException(e);
                result.resultCode = errorCode;
                return result;
            }
        }
    }
}
